# This file is part of Sonedyan.
#
# Sonedyan is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation;
# either version 3 of the License, or (at your option) any
# later version.
#
# Sonedyan is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2009-2012 Jimmy Dubuisson <jimmy.dubuisson@gmail.com>

library(igraph)
# mtx.pow
library(Biodem)
# matrix.trace
library(matrixcalc)
# 
library(gregmisc)

g <- read.graph(file = "fa-core-graphml.xml", format = "graphml")
g <- simplify(g)

# get adjacency matrix
adj <- get.adjacency(g)
n <- ncol(adj)

# 2-length cycles
adj2 <- mtx.exp(adj, 2)
tr2 <- matrix.trace(adj2)

print(paste("# 2-cycles: ", tr2 / 2))

# 3-length cycles
adj3 <- adj2 %*% adj
tr3 <- matrix.trace(adj3)

print(paste("# 3-cycles: ", tr3 / 3))

